import 'package:flutter/material.dart';
import 'package:flutter_food/core/model/meal_model.dart';
import 'package:flutter_food/core/viewmodel/favor_view_model.dart';
import 'package:flutter_food/ui/pages/detail/meal_detail_content.dart';
import 'package:provider/provider.dart';

/*
  ScrollView嵌套Column，Column嵌套ListView报错：父Widget希望子Widget有固定高度，而此时子Widget希望占据更大的空间
    ListView在垂直方向尽可能占据最大空间，Column希望所有子Widget有明确高度

   解决方案：
    1.ListView设置shrinkWrap:true，在某个范围包裹此时会多出padding，设置将padding设置为0去除默认边距
        设置physics禁止ListView滚动
    2.给ListView父容器设置固定高度，但是ListView会在父容器中滚动，看具体需求
 */

/// 定义accentColor并在CardView中使用，FloatActionButton也会引用
class MealDetailScreen extends StatelessWidget {
  static const String routeName = "/meal_detail";

  @override
  Widget build(BuildContext context) {
    final mealDetail = ModalRoute.of(context).settings.arguments as MealModel;

    return Scaffold(
      appBar: AppBar(
        title: Text('${mealDetail.title}'),
      ),
      floatingActionButton: Consumer<FavorViewModel>(
        builder: (ctx, favorVM, child) {
          final iconData = favorVM.isFavor(mealDetail)
              ? Icons.favorite
              : Icons.favorite_border;

          Color favorColor =
              favorVM.isFavor(mealDetail) ? Colors.red : Colors.black;
          return FloatingActionButton(
            child: Icon(
              iconData,
              color: favorColor,
            ),
            onPressed: () {
              favorVM.changeFavor(mealDetail);
            },
          );
        },
      ),
      body: MealDetailContent(mealDetail),
    );
  }
}
